package com.cssl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.cssl.pojo.DeptEvaluation;
import com.cssl.serice.DeptEvaluationSerice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
public class DeptEvaluationController {

    @Resource
    private DeptEvaluationSerice deptEvaluationSerice;


    @RequestMapping("/equery")
    public IPage<Map<String, Object>> equery(String name, String date, Integer pageIndex, Integer pageSize) {
        if (pageIndex == null) {
            pageIndex = 1;
        }
        IPage<Map<String, Object>> page = deptEvaluationSerice.equery(new Page<DeptEvaluation>(pageIndex, pageSize),
                new QueryWrapper<DeptEvaluation>().like(name != null, "s.name", name).like(date != null, "d.examinationdate", date));

        return page;
    }

    //添加 修改
    @RequestMapping("/esave")
    public boolean esave(DeptEvaluation deptEvaluation) {

        return deptEvaluationSerice.saveOrUpdate(deptEvaluation);
    }

    //修改单个查询
    @RequestMapping("/eq")
    public DeptEvaluation eq(int id) {
        return deptEvaluationSerice.getById(id);
    }

    //删除
    @RequestMapping("/edelete")
    public boolean edelete(String... arr) {
        return deptEvaluationSerice.removeBatchByIds(Arrays.asList(arr));
    }


        //部门绩效表查询
    @RequestMapping("/easd")
    public List<Map<String,Object>> easd(String name){
        List<Map<String,Object>> list=deptEvaluationSerice.easd(new QueryWrapper<DeptEvaluation>().
                le("d.examinationscore",name.equals("S")?100:name.equals("A")?89:name.equals("B")?79:name.equals("C")?69:name.equals("D")?59:100).
                ge("d.examinationscore",name.equals("S")?90:name.equals("A")?80:name.equals("B")?70:name.equals("C")?60:name.equals("D")?50:0));
        return  list;
        }

}
